package com.knowledge.business.controller;


import java.util.Arrays;
import java.util.List;

import com.knowledge.common.annotation.Log;
import com.knowledge.common.core.controller.BaseController;
import com.knowledge.common.core.domain.AjaxResult;
import com.knowledge.common.enums.BusinessType;
import com.knowledge.common.utils.poi.ExcelUtil;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.knowledge.business.domain.JnSysRole;
import com.knowledge.business.service.JnISysRoleService;
import com.knowledge.common.core.page.TableDataInfo;

/**
 * 锦囊管理Controller
 *
 * @author zhaoyk
 * @date 2025-09-15
 */
@RestController
@RequestMapping("/business/jnrole")
public class JnSysRoleController extends BaseController {
    @Autowired
    private JnISysRoleService sysRoleService;

    /**
     * 查询锦囊管理列表
     */
//@RequiresPermissions("business:role:list")
    @GetMapping("/list")
    public TableDataInfo list(JnSysRole sysRole) {
        startPage();
        List<JnSysRole> list = sysRoleService.selectSysRoleList(sysRole);
        return getDataTable(list);
    }

    @GetMapping("/alllist")
    public AjaxResult alllist(JnSysRole sysRole) {
        List<JnSysRole> list = sysRoleService.selectSysRoleList(sysRole);
        return AjaxResult.success(list);
    }


    /**
     * 导出锦囊管理列表
     */
    //@RequiresPermissions("business:role:export")
    @Log(title = "锦囊管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, JnSysRole sysRole) {
        List<JnSysRole> list = sysRoleService.selectSysRoleList(sysRole);
        ExcelUtil<JnSysRole> util = new ExcelUtil<JnSysRole>(JnSysRole.class);
        util.exportExcel(response, list, "锦囊管理数据");
    }

    /**
     * 获取锦囊管理详细信息
     */
    //@RequiresPermissions("business:role:query")
    @GetMapping(value = "/{roleId}")
    public AjaxResult getInfo(@PathVariable("roleId") String roleId) {
        return AjaxResult.success(sysRoleService.selectSysRoleByRoleId(roleId));
    }

    /**
     * 新增锦囊管理
     */
    //@RequiresPermissions("business:role:add")
    @Log(title = "锦囊管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JnSysRole sysRole) {
        return toAjax(sysRoleService.insertSysRole(sysRole));
    }

    /**
     * 修改锦囊管理
     */
    //@RequiresPermissions("business:role:edit")
    @Log(title = "锦囊管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JnSysRole sysRole) {
        return toAjax(sysRoleService.updateSysRole(sysRole));
    }

    /**
     * 删除锦囊管理
     */
    //@RequiresPermissions("business:role:remove")
    @Log(title = "锦囊管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{roleIds}")
    public AjaxResult remove(@PathVariable String[] roleIds) {
        return toAjax(sysRoleService.removeByIds(Arrays.asList(roleIds)));
    }
}
